/**
 * Created by syf on 2015/11/13.
 */
var express = require('express');
var router = express.Router();

var orderCtrl = require('./controllers/order');
var loginCtrl = require('./controllers/login');
var productCtrl=require("./controllers/product");

router.get('/', function (req, res, next) {
    res.render("index")
});
router.get('/index', function (req, res, next) {
    res.render("index")
});
router.get('/order', orderCtrl.getOrderListByUserID);
router.get('/order/:pageNum', orderCtrl.getOrderListByUserID);
router.get('/order/:pageNum/:name', orderCtrl.getOrderListByUserID);
router.get('/addOrder', orderCtrl.addOrderPage);
router.get('/detail', orderCtrl.detail);
router.get('/login', loginCtrl.gotoLoginPage);
router.get('/login/-5', loginCtrl.gotoLoginPage);
router.get("/addProduct",productCtrl.addProuctPage);
router.get("/product",productCtrl.productList);
router.get('/product/:pageNum', productCtrl.productList);
router.get('/product/:pageNum/:searchInfo', productCtrl.productList);
router.get('/editProduct/:productId/:backUrl', productCtrl.editProduct);
router.get("/productDetail/:productId",productCtrl.detail);
router.get("/myindex",function(req,res,next){res.render("myindex")});
router.get("/shopManagement",productCtrl.shopManage);
router.post("/shopManagement",productCtrl.saveShop);
router.get('/index/:regOut', function (req, res, next) {
    if(req.params.regOut){
        req.session.destroy();
    }
    res.render("index")
});

router.post('/order', orderCtrl.addOrder);
router.post('/login', loginCtrl.getSellerBySellerName);
router.post("/addProduct",productCtrl.addProduct);
router.post("/editProduct",productCtrl.saveProduct);
router.post("/cancelOrder",orderCtrl.cancelOrder);

module.exports = router;